package com.gg.fruit.controller;

import base.BaseServlet;
import com.gg.entity.Fruit;
import com.gg.fruit.service.FruitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/AdminGetHotFruitsServlet")
public class AdminGetHotFruitsServlet extends BaseServlet {
    @Autowired
    private FruitService fruitService;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNum=Integer.parseInt(request.getParameter("pageNum"));
        PageHelper.startPage(pageNum,8);
        Fruit fruit=new Fruit();
        fruit.setFhot(true);
        List<Fruit> fruits=fruitService.getFruitsBySearch(fruit);
        PageInfo<Fruit> hotFruitsInfo=new PageInfo<>(fruits);
        request.getSession().setAttribute("fruitsInfo",hotFruitsInfo);
        request.getSession().setAttribute("isHot",true);
        response.sendRedirect("/fruits/admin/BSindex4.jsp");
    }
}
